package com.fh.db.oracle;

import com.fh.db.SqlSet;

/**
 * @Author qiujunda
 * @Date 16/05/2020
 * @Description
 */
public class OracleSqlSet implements SqlSet {
    @Override
    public String viewSql() {
        return null;
    }

    @Override
    public String viewPreSql() {
        return "SELECT OWNER, VIEW_NAME, TEXT_LENGTH,TEXT,U.CREATED,U.LAST_DDL_TIME FROM ALL_VIEWS V,USER_OBJECTS U WHERE V.OWNER = ? AND U.OBJECT_NAME=V.VIEW_NAME AND U.OBJECT_TYPE = 'VIEW' AND V.VIEW_NAME LIKE 'CUX%'";
    }

    @Override
    public String tablePreSql() {
        return "SELECT V.OWNER,V.TABLE_NAME,V.TABLESPACE_NAME,V.NUM_ROWS,A.COMMENTS,U.CREATED, U.LAST_DDL_TIME FROM ALL_TABLES V, ALL_OBJECTS U,ALL_TAB_COMMENTS A WHERE " +
                " A.OWNER=V.OWNER AND A.TABLE_NAME=V.TABLE_NAME AND V.OWNER='CUX' AND V.TABLE_NAME LIKE 'CUX%' AND U.OBJECT_NAME = V.TABLE_NAME AND U.OWNER=V.OWNER AND U.OBJECT_TYPE = 'TABLE'";
    }

    @Override
    public String columnPreSql() {
        return "SELECT B.OWNER,B.TABLE_NAME,B.COLUMN_NAME,B.DATA_TYPE,B.DATA_LENGTH,B.DATA_PRECISION,B.NULLABLE,B.COLUMN_ID,C.COMMENTS" +
                " FROM ALL_TAB_COLUMNS B,ALL_COL_COMMENTS C WHERE C.OWNER=B.OWNER AND C.TABLE_NAME=B.TABLE_NAME" +
                "  AND C.COLUMN_NAME=B.COLUMN_NAME AND B.TABLE_NAME = ? AND B.OWNER=? ";
    }

    @Override
    public String indexPreSql() {
        return "SELECT OWNER,UNIQUENESS,INDEX_TYPE,INDEX_NAME FROM ALL_INDEXES WHERE TABLE_NAME=? AND OWNER=?  ";
    }

    @Override
    public String indexColumnPreSql() {
        return "SELECT COLUMN_NAME,COLUMN_POSITION,DESCEND FROM ALL_IND_COLUMNS WHERE INDEX_NAME = ? AND INDEX_OWNER=? ";
    }

    @Override
    public String packagePreSql() {
        return "SELECT A.OWNER, A.OBJECT_NAME, A.CREATED, A.LAST_DDL_TIME P_LAST_DDL_TIME,B.LAST_DDL_TIME B_LAST_DDL_TIME" +
                "  FROM ALL_OBJECTS A ,ALL_OBJECTS B" +
                " WHERE A.OBJECT_TYPE = 'PACKAGE'" +
                "   AND A.OWNER = 'APPS'" +
                "   AND A.OWNER=B.OWNER" +
                "   AND A.OBJECT_NAME=B.OBJECT_NAME" +
                "   AND B.OBJECT_TYPE='PACKAGE BODY'" +
                "   AND A.OBJECT_NAME LIKE 'CUX%'";
    }

    @Override
    public String packageDeclearPreSql() {
        return "SELECT LINE,TEXT FROM ALL_SOURCE WHERE NAME= ? AND  OWNER=? AND TYPE='PACKAGE' ORDER BY LINE ASC";
    }

    @Override
    public String packageBodyPreSql() {
        return "SELECT LINE,TEXT FROM ALL_SOURCE WHERE NAME= ? AND  OWNER=? AND TYPE='PACKAGE BODY' ORDER BY LINE ASC";
    }

}
